#include "stdafx.h"
#include "BadOrange.h"
#include "Drawing.h"
#ifdef SCRNSAVER
HINSTANCE hInst;
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
VOID LoadVideo(HWND hwnd);

LONG WINAPI ScreenSaverProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	if(msg==WM_CREATE){
		D3D_CaptureScreen();
		D3D_fullScreen = FALSE;
		if(D3D_CreateThread(hWnd)==NULL){
			REPORT_ERROR("D3D_CreateThread failed.");
			PostQuitMessage(0);
		}
		return 0;
	}else if(MyWndProc(hWnd,msg,wParam,lParam)){
		return 0;
	}
	return DefScreenSaverProc(hWnd,msg,wParam,lParam);
}

BOOL WINAPI RegisterDialogClasses(HANDLE inst)
{
	hInst=(HINSTANCE)inst;
	TCHAR buf[65536];
	LoadString(hInst,IDS_ABOUT,buf,65536);
	MessageBox(hMainWindow,buf,_T("About"),MB_OK);
/*
	HWND hWnd = CreateDialog((HINSTANCE)inst,MAKEINTRESOURCE(IDD_CONFIG),NULL,(DLGPROC)ScreenSaverConfigureDialog);
	if(NULL==hWnd)return false;
	ShowWindow(hWnd,SW_SHOW);
	BOOL bRet;
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0) != 0){ 
		TranslateMessage(&msg); 
		DispatchMessage(&msg); 
	}
*/
	return FALSE;
}

BOOL WINAPI ScreenSaverConfigureDialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	
	switch(msg){
	case WM_COMMAND:
		switch(LOWORD(wParam)){
		case IDC_ABOUT:{
			//DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, About);
			TCHAR buf[65536];
			LoadString(hInst,IDS_ABOUT,buf,65536);
			MessageBox(hWnd,buf,_T("About"),MB_OK);
			break;
		}
		case IDC_BTNOPEN:
			LoadVideo(hWnd);
			break;
		case IDOK:
		case IDCANCEL:
			PostQuitMessage(0);
			break;
		}
	default:
		return DefWindowProc(hWnd,msg,wParam,lParam);
	}
	return TRUE;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
        UNREFERENCED_PARAMETER(lParam);
        switch (msg)
        {
        case WM_INITDIALOG:{
			HWND txt = GetDlgItem(hDlg,IDC_ABOUTTEXT);
			TCHAR buf[65536];
			LoadString(hInst,IDS_ABOUT,buf,65536);
			SetWindowText(txt,buf);
			return TRUE;
		}
		
        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL){
				EndDialog(hDlg, LOWORD(wParam));
                return TRUE;
			}
            break;
		default:
			return DefWindowProc(hDlg,msg,wParam,lParam);
        }
        return TRUE;
}

VOID LoadVideo(HWND hwnd){
	OPENFILENAME ofn;       // common dialog box structure
	TCHAR szFile[260];       // buffer for file name

	// Initialize OPENFILENAME
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hwnd;
	ofn.lpstrFile = szFile;
	// Set lpstrFile[0] to '\0' so that GetOpenFileName does not 
	// use the contents of szFile to initialize itself.
	ofn.lpstrFile[0] = '\0';
	ofn.nMaxFile = sizeof(szFile);
	ofn.lpstrFilter = L"AVI Video\0*.avi";
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = NULL;
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

	// Display the Open dialog box. 

	if (GetOpenFileName(&ofn)==TRUE){
		 
	}
}
#endif
